package tjs.study.notes.jvm.utils.jarClash;

import java.net.MalformedURLException;
import java.net.URL;
import java.util.List;

/**
 * Created by Nicky.Tang on 2021/10/19 11:55 上午
 *
 * @since 02.12.10
 */
public class ModuleSelfClassLoader extends AbtractSelfClassLoader {

    public ModuleSelfClassLoader(List<String> urlStrs, ClassLoader parent) {
        super(toURLs(urlStrs), parent);
    }

    public static URL[] toURLs(List<String> urlStrs) {
        URL[] urls = new URL[urlStrs.size()];
        for (int i = 0; i < urlStrs.size(); i++) {
            try {
                urls[i] = new URL("file:" + urlStrs.get(i));
            } catch (MalformedURLException e) {
                e.printStackTrace();
            }
        }
        return urls;
    }

    @Override
    public Class<?> loadClass(String name, boolean resolve) throws ClassNotFoundException {
        return super.loadBySelfFirst(name, resolve);
    }
}
